package com.suitsoft.ut.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

/**
 * 文件拷贝类.
 *  
 * @author coombe
 */
public class FileCopy {
	/** 缓冲区大小 */
	private static final int BUFFER_SIZE = 16384;
	
	/**
	 * 文件拷贝.
	 * 
	 * @param srcFileName	源文件路径和文件名
	 * @param destPath		目标文件夹
	 * @param fileName		文件名
	 * @throws IOException
	 */
	public void copy(String srcFileName, String destPath, String fileName) throws IOException {
		File destFile = new File(destPath);
		if (!destFile.exists()) {
			destFile.mkdirs();
		}
		
		InputStream is = new FileInputStream(srcFileName);
		OutputStream os = new FileOutputStream(destPath + fileName);
		
		int len;
		byte[] buff = new byte[BUFFER_SIZE];
		while((len = is.read(buff)) != -1) {
			os.write(buff, 0, len);
		}
		
		os.flush();
		is.close();
		os.close();
	}
}
